package net.lainiao.zhihu.reptitle;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

/**
 * Created by Administrator on 2016/1/15.
 */
public class ZhihuhualinksHtml {
    public static List<String> getLinks(String url) throws IOException, SAXException, InterruptedException {
        Document document=HtmlCommon.getDocument(url);
        String question_regex="^/question/[0-9]+";
        List<String> list=new ArrayList<String>();
        Elements elements=document.select(".zm-item").select("a");
        for(Element element:elements){
            String href=element.attr("href");
            if(Pattern.matches(question_regex, href)) {
                list.add(href);
            }
        }
        return list;
    }
}
